﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace IPMSG
{
    public class EventPublicator
    {
        private static EventPublicator instance = new EventPublicator();

        //单件模式
        public static EventPublicator Instance
        {
            get { return instance; }
        }

        /// <summary>
        /// 用户加入列表
        /// </summary>
        public event EventHandler<UserEventArgs> UserEntryEvent;

        /// <summary>
        /// 用户退出
        /// </summary>
        public event EventHandler<UserEventArgs> UserExitEvent;

        /// <summary>
        /// 收到新消息
        /// </summary>
        public event EventHandler<MessageRcvArgs> MessageRcvEvent;

        internal void OnUserEntryEvent(UserEventArgs e)
        {
            if (this.UserEntryEvent != null)
            {
                this.UserEntryEvent(this, e);
            }
        }

        internal void OnUserExitEvent(UserEventArgs e)
        {
            if (this.UserExitEvent != null)
            {
                this.UserExitEvent(this, e);
            }
        }

        internal void OnMessageRcvEvent(MessageRcvArgs e)
        {
            if (this.MessageRcvEvent != null)
            {
                this.MessageRcvEvent(this, e);
            }
        }
    }

    public class UserEventArgs : EventArgs
    {
        public string Ip { get; private set; }
        public string UserName { get; private set; }
        public string HostName { get; private set; }

        public UserEventArgs(string ip, string userName, string hostName)
        {
            Ip = ip;
            UserName = userName;
            HostName = hostName;
        }
    }

    public class MessageRcvArgs : EventArgs
    {
        public string HostName { get; private set; }
        public string Message { get; private set; }

        public MessageRcvArgs(string hostName, string message)
        {
            HostName = hostName;
            Message = message;
        }
    }
}
